#include "thread_test.h"

#include "include/toolkit/thread_kit.h"

using namespace wel;

CPPUNIT_TEST_SUITE_REGISTRATION( CThreadTest );

UINT ThreadProc_BAC(void *pParam)
{
	return  *(UINT *)pParam;
}

class CTestActive:public CActiveObject
{
public:
	CTestActive()
		:m_iCheck(0)
	{

	}

protected:
	UINT Work()
	{
		m_iCheck  = 520;

		return 1314;
	}

public:
	int m_iCheck;
};

void CThreadTest::TestBase()
{
	CThreadWrapper tw;

	UINT ret = 10;
	tw.Create( ThreadProc_BAC, &ret );
	UINT code = 0;
	tw.WaitFor( &code );
	CPPUNIT_ASSERT( code == ret );


	CTestActive at;

	CPPUNIT_ASSERT( at.Active() );
	at.WaitFor( &code );
	CPPUNIT_ASSERT( at.m_iCheck == 520 );
	CPPUNIT_ASSERT( !at.IsWork() );
	CPPUNIT_ASSERT( code == 1314 );
}
